import pika
import time
import logging

#logging.basicConfig(level=logging.DEBUG)

ITERATIONS = 10000

connection = pika.BlockingConnection(pika.URLParameters('amqp://admin:admin@192.168.1.5:5672/%2F?heartbeat_interval=1'))
channel = connection.channel()

def closeit():
    print('Close it')
    connection.close()

connection.add_timeout(5, closeit)

#connection.sleep(100)
#channel.exchange_declare(exchange = "hello-exchange", type = "direct", passive = False, durable = True, auto_delete = True)

#channel.confirm_delivery()
start_time = time.time()

for x in range(0, ITERATIONS):
    channel.basic_publish(exchange='hello-exchange',
                                 routing_key='hi',
                                 body='Test',
                                 properties=pika.BasicProperties(content_type='text/plain',delivery_mode=1))


channel.close()
connection.close()

duration = time.time() - start_time
print("Published %i messages in %.4f seconds (%.2f messages per second)" % (ITERATIONS, duration, (ITERATIONS/duration)))

